package com.health.web.controller.teahouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.teahouse.domain.Vegetables;
import com.health.teahouse.service.IVegetablesService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 蔬菜信息Controller
 * 
 * @author yang
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/teahouse/vegetables")
public class VegetablesController extends BaseController
{
    @Autowired
    private IVegetablesService vegetablesService;

    /**
     * 查询蔬菜信息列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vegetables:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vegetables vegetables)
    {
        startPage();
        List<Vegetables> list = vegetablesService.selectVegetablesList(vegetables);
        return getDataTable(list);
    }

    /**
     * 导出蔬菜信息列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vegetables:export')")
    @Log(title = "蔬菜信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vegetables vegetables)
    {
        List<Vegetables> list = vegetablesService.selectVegetablesList(vegetables);
        ExcelUtil<Vegetables> util = new ExcelUtil<Vegetables>(Vegetables.class);
        util.exportExcel(response, list, "蔬菜信息数据");
    }

    /**
     * 获取蔬菜信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vegetables:query')")
    @GetMapping(value = "/{vegetableId}")
    public AjaxResult getInfo(@PathVariable("vegetableId") Long vegetableId)
    {
        return success(vegetablesService.selectVegetablesByVegetableId(vegetableId));
    }

    /**
     * 新增蔬菜信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vegetables:add')")
    @Log(title = "蔬菜信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vegetables vegetables)
    {
        return toAjax(vegetablesService.insertVegetables(vegetables));
    }

    /**
     * 修改蔬菜信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vegetables:edit')")
    @Log(title = "蔬菜信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vegetables vegetables)
    {
        return toAjax(vegetablesService.updateVegetables(vegetables));
    }

    /**
     * 删除蔬菜信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:vegetables:remove')")
    @Log(title = "蔬菜信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vegetableIds}")
    public AjaxResult remove(@PathVariable Long[] vegetableIds)
    {
        return toAjax(vegetablesService.deleteVegetablesByVegetableIds(vegetableIds));
    }
}
